package com.whales.lms.rms.web.controller;

import java.io.File;
import java.util.List;

import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.whales.lms.rms.web.model.ManualVO;
import com.whales.lms.rms.web.service.ManualService;
import com.whales.shared.controller.GenericController;
import com.whales.shared.model.CommonVO;
import com.whales.shared.util.FileUtil;

@Controller
@RequestMapping("/manual/*")
public class ManualController extends GenericController<ManualVO, ManualVO, ManualService>{
	@RequestMapping
	public @ResponseBody List<ManualVO> getManualByParentId(ManualVO manualVO) throws Exception{
		return service.getManualByParentId(manualVO);
	}
	
	@RequestMapping
	public @ResponseBody String deleteByParentId(CommonVO manualVO) throws Exception{
		service.deleteByParentId(manualVO);
		return super.SUCCESS_JSON_STRING;
	}
	
	@RequestMapping
	public void downloadManual(HttpServletResponse response,ManualVO manualVO) throws Exception{
		ManualVO manualFile = service.findInfo(manualVO);
		FileUtil.fileDownload(new File(manualFile.getSvrPath()), manualFile.getFileName(), response);
	}
}
